using System;
using CustomerContactSystem.Core.Infrastructure.Domain;

namespace CustomerContactSystem.Core.Model {
    public class EnquiryClosure : Entity {
        public virtual DateTime DateClosed { get; set; }
        public virtual User ClosedBy { get; set; }
        public virtual Department ClosedByDepartment { get; set; }
        public virtual UserGroup ClosedByGroup { get; set; }
        public virtual bool CustomerWasContacted { get; set; }
        public virtual string CustomerWasContactedBy { get; set; }
        public virtual bool DeadlineMet { get; set; }
        public virtual string EnquiryResponse { get; set; }

        protected override void Validate() {
            if (DateClosed == DateTime.MinValue) {
                AddBrokenRule(new BusinessRule("DateClosed", "Date closed is required!"));
            }

            if (ClosedBy == null || ClosedBy.Id == 0) {
                AddBrokenRule(new BusinessRule("ClosedBy", "Closed by is required!"));
            }

            if (ClosedByDepartment == null || ClosedByDepartment.Id == 0) {
                AddBrokenRule(new BusinessRule("ClosedByDepartment", "Closed by department is required!"));
            }

            if (ClosedByGroup == null || ClosedByGroup.Id == 0) {
                AddBrokenRule(new BusinessRule("ClosedByGroup", "Closed by group is required!"));
            }

            if (string.IsNullOrEmpty(EnquiryResponse)) {
                AddBrokenRule(new BusinessRule("EnquiryResponse", "Enquiry response is required!"));
            }
        }
    }
}